import java.awt.*;
import java.util.List;

public class Snake {

    public void move(List<Point> snake, String direction, Point foodPosition) {
        Point currentHead = snake.get(0);
        // 计算新的蛇头位置
        Point newHeadPos = new Point(currentHead.x, currentHead.y);
        switch (direction) {
            case "up":
                newHeadPos.y++;
                break;
            case "down":
                newHeadPos.y--;
                break;
            case "left":
                newHeadPos.x--;
                break;
            case "right":
                newHeadPos.x++;
                break;
            default:
                throw new IllegalComponentStateException("Invalid direction");
        }
        // 添加新的蛇头位置
        snake.add(0, newHeadPos);
        if (!newHeadPos.equals(foodPosition)) {
            snake.remove(snake.size() - 1);
        }
    }
    public static void main(String[] args) {

    }
}
